package com.sefon.autocreate;

import java.io.File;
import java.io.IOException;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.text.DecimalFormat;
import java.util.Random;

public class MysqlDemo {

	
	public static String getCode(String sql) throws SQLException {
		Connection conn = null;
		String url = "jdbc:mysql://10.0.10.67:3306/springcloud?user=root&password=&useUnicode=true&characterEncoding=UTF8";

		try {
			Class.forName("com.mysql.jdbc.Driver");
			conn = DriverManager.getConnection(url);
			Statement stmt = conn.createStatement();
			ResultSet rs = stmt.executeQuery(sql);
			while (rs.next()) {
				return rs.getString(1);
			}
		} catch (SQLException e) {
			System.out.println("MySQL操作错误");
			e.printStackTrace();
		} catch (Exception e) {
			e.printStackTrace();
		} finally {
			conn.close();
		}
		return null;
	}
	public static void main(String[] args) throws IOException {
		DecimalFormat df = new DecimalFormat("0.00");
		System.out.println(df.format(new Random().nextDouble()));
	    File directory = new File("");//设定为当前文件夹  
        System.out.println(directory.getCanonicalPath());//获取标准的路径  
        System.out.println(directory.getAbsolutePath());//获取绝对路径  
        
	}
}